package com.leetcode.string;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Dennis Li
 * @date 2020/7/29 10:34
 */
public class IsPalindrome_9 {

    public boolean isPalindrome(int x) {
        if (x < 0) return false;
        List<Integer> list = new ArrayList<>();
        while (x > 0) {
            list.add(x % 10);
            x /= 10;
        }
        int len = list.size();
        for (int i = 0, j = len - 1; i < j; i++, j--) {
            if (!list.get(i).equals(list.get(j))) return false;
        }
        return true;
    }

    public boolean isPalindrome2(int x) {
        if (x < 0) return false;
        String s = String.valueOf(x);
        for (int i = 0, j = s.length() - 1; i < j; i++, j--) {
            if(s.charAt(i) != s.charAt(j)) return false;
        }
        return true;
    }

}
